<?php
namespace backend\controllers;

use Yii;
use yii\web\Controller;
use common\collection\Common;
use common\helpers\PublicFun;
use backend\config\routeParams;

/**
 * Login controller
 */
class LoginController extends Controller
{
    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
        ];
    }


    public  function beforeAction($action){
        return true;
    }
    //首页
    public function actionIndex()
    {
        return $this->render('index');
    }

    //登录
    public function actionLoginin(){
        $callback = Yii::$app->request->get('callback');
        //JsonData接收Resquest的参数
        $JsonData = Yii::$app->request->post('data');
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        $JsonData['AuthId'] = Common::CreateGuid();
        //经过所有的验证 调用登录接口获取用户信息
        $url = routeParams::HttpUrl('AdminLogin');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        if($result['IsBizSuccess']){  //登记登录成功
            // 从"response"组件中获取cookie 集合(yii\web\CookieCollection)
            $cookies = Yii::$app->response->cookies;
            // 在要发送的响应中添加一个新的cookie
            $cookies->add(new \yii\web\Cookie([
                'name' => 'MytipIdBack',
                'value' => $result['MytipInfo']['MytipId'],
                'expire'=>time()+60*60*24*30,
            ]));
            Yii::$app->response->send();
            //die();
            echo $callback . "(" . json_encode($result) . ")";exit;
        }else{
            echo $callback . "(" . json_encode($result) . ")";exit;
        }
    }



    //注册
//    public  function  actionRegister(){
//        return $this->render('register');
//    }
    //注册
    public  function  actionForgot(){
        return $this->render('forgot');
    }
    //退出登录
    public  function  actionLogout(){


    }


}
